﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SarsClient.GUI
{
    public partial class ControlCenter : Form
    {
    	
    	// Action run to exit application
		public DelExitApp OnExitApp;
		
		// Register own action implementations on controller
		public void SubscribeOnController(MainController ctrlr){
		}
		
    	
    	public DelConnectToIp OnConnectToIp;
    	
        public ControlCenter()
        {
            InitializeComponent();
            Logging.Logger.Debug("");
            Logging.Forwarder.AddAppender(this.log4NetCtrl1.Appender);
            this.ipTextBox1.IPAddress = System.Net.IPAddress.Loopback;
            this.ipTextBox1.TextChanged += delegate(object sender, EventArgs e) { if (this.ipTextBox1.IPAddress == null) this.errorProvider1.SetError(this.ipTextBox1,"Invalid IP Address!"); else this.errorProvider1.Clear(); this.cloudButton1.Enabled = this.ipTextBox1.IPAddress != null; };
        }

        private void treeViewBuddy_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }
        
        void IpTextBox1Load(object sender, EventArgs e)
        {
        	
        }
        
        void CloudButton1Click(object sender, EventArgs e)
        {
        	this.OnConnectToIp(this.ipTextBox1.IPAddress);
        }
        
        void ControlCenterFormClosed(object sender, FormClosedEventArgs e)
        {
        	Logging.Forwarder.RemoveAppender(this.log4NetCtrl1.Appender);
        	this.OnExitApp.Invoke();
        }
        
        void IpTextBox1KeyPress(object sender, KeyPressEventArgs e)
        {
        	if (e.KeyChar == (char)13 && cloudButton1.Enabled)
        		this.CloudButton1Click(null,null);
        }
    }
}
